package model.ability;

import model.core.Logger;
import model.effects.Effect;
import model.entity.Entity;
import model.map.MapPoint;

/**
 * This class defines abilities that can be done anywhere on the map
 * by the caster, from a hotkey.  These abilities are done straight 
 * ahead of the caster.
 * @author Zachary
 */
public class StraightAheadAbility extends DurationAbility {
	/**
	 * Constructor for a StraightAheadAbility.
	 */
	public StraightAheadAbility(String name, PassiveSkill ps, int mana, int delay,
			Effect baseEffect, AbilityType at, String graphicID, 
			int duration) {
		super(name, ps, mana, delay, baseEffect, at, graphicID, duration);
	}
	
	/**
	 * Call this method to use a RangedMapAbility.
	 * @param h
	 */
	public void useMapAbility(Entity caster){
		if(this.testProbability())
			this.doStraightAheadAbility(caster);
		else
			Logger.getInstance().writeToLogger("Ability failed!");
		caster.diasbleAttack(this.getDelay());
	}
	
	/**
	 * Propagates ability when called.
	 * @param h
	 */
	private void doStraightAheadAbility(Entity caster){
		MapPoint castPoint = caster.getLocation();
		MapPoint direction = caster.getDirection();
		Effect effect = this.getDerivedEffect(caster);
		MapPoint skillObjectPoint = MapPoint.addPoints(castPoint, direction);
		
		StraightAheadAbilityHandler h = HandlerFactory.createStraightAheadAbilityHandler();
		h.run(this, effect, caster, castPoint, skillObjectPoint);
	}
}
